﻿const workController = require('../../controllers/editor/editor');
const tokens = require('../../services/tokenService');

module.exports = app => {
  const express = require('express');
  const router = express.Router();

  router.all('*',function (req,res,next) {
    if (req.header('s-token')) {
      tokens.checkToken(req.header('s-token'), function (err,decode) {
        if (err) return res.send({code: 50014, message: '身份校验失败'});
        req.decode = decode;
      })
    }
    next()
  });

  router.get('/scratch/upload', workController.scratchWorkUpload);

  router.get('/scratch/teach/:id', workController.getTeachURL);
  router.get('/scratch/update/:id',workController.getUpdateURL);
  router.get('/scratch/create/:id',workController.getCreateURL);

  router.get('/extensions/speech2text/token', workController.baiduToken);
  router.post('/extensions/speech2text/server', workController.baiduServer);
  router.get('/extensions/weather/:weather', workController.getWeather);

  app.use('/work', router);
};
